package com.yf.bean;

import lombok.Data;

@Data
public class BaseResponse<T> {
    String msg;
    Integer code;
    T data;

    BaseResponse() {}
    BaseResponse(StatusCode code, T data) {
        this.msg = code.msg;
        this.code = code.code;
        this.data = data;
    }

    BaseResponse(String msg, Integer code,T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static<T> BaseResponse<T> fail(T data) {
        return new BaseResponse<>(StatusCode.Failed, data);
    }
    public static<T> BaseResponse<T> fail() {
        return new BaseResponse<>(StatusCode.Failed, null);
    }

    public static<T> BaseResponse<T> of(StatusCode status,T data) {
        return new BaseResponse<>(status, data);
    }
    public static<T> BaseResponse<T> of(StatusCode status) {
        return new BaseResponse<>(status, null);
    }

    public static<T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(StatusCode.Success, data);
    }

    public static<T> BaseResponse<T> success() {
        return new BaseResponse<>(StatusCode.Success, null);
    }

    public static<T> BaseResponse<T> success(String msg, Integer code, T data) {
        return new BaseResponse<>(msg, code, data);
    }

    public static<T> BaseResponse<T> fail(String msg, Integer code, T data) {
        return new BaseResponse<>(msg, code, data);
    }
}
